// 初始化路由及注册
// @author ishot

package router

import (
	"admin-go-api/api"
	"admin-go-api/config"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func InitRouter() *gin.Engine {
	// 设置启动模式
	gin.SetMode(config.Config.System.Env)
	router := gin.New()
	// 宕机时恢复
	router.Use(gin.Recovery())
	// register 注册
	register(router)
	return router
}

// register 路由接口
func register(router *gin.Engine) {
	// todo 后续接口url
	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	router.GET("/api/success", api.Success)
	router.GET("/api/failed", api.Failed)
	// 菜单相关接口
	router.POST("/api/sysMenu/add", api.CreateSysMenu)
	router.GET("/api/sysMenu/list", api.GetSysMenuList)
	router.GET("/api/sysMenu/info", api.GetSysMenu)
	router.PUT("/api/sysMenu/update", api.UpdateSysMenu)
	router.DELETE("/api/sysMenu/delete", api.DeleteSysMenu)
	// 角色相关接口
	router.POST("/api/sysRole/add", api.CreateSysRole)
	router.GET("/api/sysRole/list", api.GetSysRoleList)
	router.GET("/api/sysRole/info", api.GetSysRole)
	router.PUT("/api/sysRole/update", api.UpdateSysRole)
	router.DELETE("/api/sysRole/delete", api.DeleteSysRole)
	router.PUT("/api/sysRole/updateStatus", api.UpdateSysRoleStatus)
	router.GET("/api/sysRole/vo/list", api.GetSysRoleVoList)
	router.GET("/api/sysRole/vo/idList", api.QueryRoleMenuIdList)
	router.PUT("/api/sysRole/assignPermissions", api.AssignPermissions)
	// 用户相关接口
	router.POST("/api/sysAdmin/add", api.CreateSysAdmin)
	router.GET("/api/sysAdmin/info", api.GetSysAdmin)
	router.PUT("/api/sysAdmin/update", api.UpdateSysAdmin)
	router.DELETE("/api/sysAdmin/delete", api.DeleteSysAdmin)
	router.PUT("/api/sysAdmin/updateStatus", api.UpdateSysAdminStatus)
	router.PUT("/api/sysAdmin/updatePassword", api.ResetSysAdminPassword)
	router.GET("/api/sysAdmin/list", api.GetSysAdminList)
	router.POST("/api/sysAdmin/login", api.Login)
	// 前端
	router.GET("/api/captcha", api.Captcha)
}
